package com.ruoyi.project.cms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.project.cms.domain.BizResume;
import com.ruoyi.project.cms.domain.BizStudentPostVo;
import com.ruoyi.project.cms.mapper.BieStudentPostMapper;
import com.ruoyi.project.cms.service.IBizResumeService;
import com.ruoyi.project.system.domain.SysUser;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.cms.domain.BieStudentPost;
import com.ruoyi.project.cms.service.IBieStudentPostService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 学生-企业关联Controller
 *
 * @author ruoyi
 * @date 2023-03-18
 */
@RestController
@RequestMapping("/cms/student_post")
public class BieStudentPostController extends BaseController
{
    @Autowired
    private IBieStudentPostService bieStudentPostService;
    //20230319

    @Autowired
    private IBizResumeService bizResumeService;

    @Autowired
    private BieStudentPostMapper bieStudentPostMapper;

    /**
     * 查询学生-企业关联列表
     */
    @PreAuthorize("@ss.hasPermi('cms:student_post:list')")
    @GetMapping("/list")
    public TableDataInfo list(BieStudentPost bieStudentPost)
    {
        startPage();
        //List<BieStudentPost> list = bieStudentPostService.selectBieStudentPostList(bieStudentPost);
        List<BizStudentPostVo> list = bieStudentPostMapper.findAll();

        return getDataTable(list);
    }

    /**
     * 导出学生-企业关联列表
     */
    @PreAuthorize("@ss.hasPermi('cms:student_post:export')")
    @Log(title = "学生-企业关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BieStudentPost bieStudentPost)
    {
        List<BieStudentPost> list = bieStudentPostService.selectBieStudentPostList(bieStudentPost);
        ExcelUtil<BieStudentPost> util = new ExcelUtil<BieStudentPost>(BieStudentPost.class);
        util.exportExcel(response, list, "学生-企业关联数据");
    }

    /**
     * 获取学生-企业关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:student_post:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bieStudentPostService.selectBieStudentPostById(id));
    }

    /**
     * 新增学生-企业关联
     */
    @PreAuthorize("@ss.hasPermi('cms:student_post:add')")
    @Log(title = "学生-企业关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BieStudentPost bieStudentPost)
    {
        return toAjax(bieStudentPostService.insertBieStudentPost(bieStudentPost));
    }

    /**
     * 修改学生-企业关联
     */
    @PreAuthorize("@ss.hasPermi('cms:student_post:edit')")
    @Log(title = "学生-企业关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BieStudentPost bieStudentPost)
    {
        return toAjax(bieStudentPostService.updateBieStudentPost(bieStudentPost));
    }

    /**
     * 删除学生-企业关联
     */
    @PreAuthorize("@ss.hasPermi('cms:student_post:remove')")
    @Log(title = "学生-企业关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bieStudentPostService.deleteBieStudentPostByIds(ids));
    }
    /**
     * 学生-投递简历
     */
    @PostMapping("/add2")
    @PreAuthorize("@ss.hasPermi('cms:student_post:edit')")
    public AjaxResult add2(@RequestBody BieStudentPost  bieStudentPost){
        SysUser user = SecurityUtils.getLoginUser().getUser();
        //查找自己的简历
        BizResume bizResume = new BizResume();
        bizResume.setUserId(user.getUserId());
        List<BizResume> bizResumes = bizResumeService.selectBizResumeList(bizResume);
        if(bizResumes.size()==0){
            return AjaxResult.error("没有简历");
        }else {
            Long resumesId = bizResumes.get(0).getId();
            bieStudentPost.setUserId(user.getUserId());
            bieStudentPost.setResumeId(resumesId);
            bieStudentPostService.insertBieStudentPost(bieStudentPost);
            return AjaxResult.success("投递成功");
        }
    }
    /**
     * 企业-同意学生的投递
     */
}
